<template>
  <view style="background-color: #fff;">
    <comboGrid requestUrl="/wms/wmsLocationCapacity/getLocationByWarehouseCodeForCCP" :requestParam="data.requestParam"
      :column="data.column"></comboGrid>
    <view @click="open">打开签名 {{ $t('translationImage.processInspection') }}</view>
    <qiun-data-charts type="column" :chartData="data.chartData" />

  </view>
</template>

<script setup>
import { onMounted, reactive, ref } from "vue";
import { navigate } from '@/utils/routerSkip.js';
import comboGrid from "@/components/comboGrid";
import miliuAutograph from "@/components/miliu-autograph/miliu-autograph";
components: {
  comboGrid,
    miliuAutograph
}
let isCanvas = ref(false)
const data = reactive({
  chartData: {},
  websocket: {},
  requestParam: {
    warehouseCode: "RM",
  },
  column: [
    {
      label: "仓库名",
      name: "locationName",
    },
    {
      label: "仓库容量",
      name: "maxCapacity",
    },
  ],
});
onMounted(() => {
  initWebSocket();
  test()
  // getDeviceIp()
  // getDeviceMac()
  getServerData()
});
const getServerData = () => {
  //模拟从服务器获取数据时的延时
  setTimeout(() => {
    let res = {
      categories: ["2016", "2017", "2018", "2019", "2020", "2021"],
      series: [
        {
          name: "目标值",
          data: [35, 36, 31, 33, 13, 34]
        },
        {
          name: "完成量",
          data: [18, 27, 21, 24, 6, 28]
        }
      ]
    };
    data.chartData = JSON.parse(JSON.stringify(res));
  }, 500);
}

const initWebSocket = () => {
  //如果是https的话，端口是13529
  data.websocket = new WebSocket("ws://127.0.0.1:5000");

  data.websocket.onopen = websocketonopen;
  data.websocket.onerror = websocketonerror;
  data.websocket.onmessage = websocketonmessage;
};
// 打开连接
const websocketonopen = () => {
  console.log("打印组件已开启");
  let data = {
    cmd: "getPrinters",
    requestID: getUid, //用户id
    version: "1.0",
  };
  //发送获取打印机列表命令
  data.websocket.send(JSON.stringify(data));
};

// websocket连接错误
const websocketonerror = (e) => {
  console.log("打印组件未开启，请确认打印组件是否开启");
};

// websocket接收信息
const websocketonmessage = (e) => {
  //接收数据;
  const result = JSON.parse(e.data);

  //收到打印机列表数据
  if (result.cmd == "getPrinters") {
    this.printerList = result.printers; // 本机连接的打印机列表信息
  }

  // 打印成功处理逻辑
  if (result.status == "completeSuccess") {
    this.$message.success("打印成功");

    // 调接口，刷新打印次数
    updatePrintCount({
      ids: this.ids,
      printCount: this.dialogForm.printNum,
    }).then((res) => {
      this.resetTable = !this.resetTable; // 刷新主页面接口的标识符
    });
  }
};
const open = () => {
  navigate({
    url: `/pages/check/signature`
  })
}
const test = () => {
  var net = plus.android.importClass("java.net.NetworkInterface")
  var wl0 = net.getByName('wlan0')
  var macByte = wl0.getHardwareAddress()
  var str = ''
  //下面这段代码来自网络  
  for (var i = 0; i < macByte.length; i++) {
    var tmp = "";
    var num = macByte[i];
    if (num < 0) {
      tmp = (255 + num + 1).toString(16);
    } else {
      tmp = num.toString(16);
    }
    if (tmp.length == 1) {
      tmp = "0" + tmp;
    }
    str += tmp;
  }
  console.log(str, '---获取mac地址----')
}
</script>

<style lang="scss">
.setclass {
  width: 100%;
  height: 800rpx;
}
</style>
